package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.gigi.model.FileDO;
import com.gigi.model.IdRequest;
import com.gigi.model.ListFolderRequest;
import com.gigi.service.manual.FileManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 文件夹管理
 */
@RestController
@RequestMapping("file-manage")
public class FileManageController {

    private final FileManageService folderManageService;

    public FileManageController(FileManageService folderManageService) {
        this.folderManageService = folderManageService;
    }

    @ApiOperation(value = "列表")
    @PostMapping("/list")
    public MultiResponse<FileDO> list(@RequestBody ListFolderRequest request) {
        return folderManageService.list(request);
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public Response save(@RequestBody FileDO request) {
        return folderManageService.save(request);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public Response delete(@RequestBody @Valid IdRequest request) {
        return folderManageService.delete(request.getId());
    }

}
